package com.nbsaas.sample.controller.user;

import com.nbsaas.boot.rest.annotations.Add;
import com.nbsaas.boot.rest.annotations.Delete;
import com.nbsaas.boot.rest.annotations.Update;
import com.nbsaas.boot.rest.annotations.View;
import com.nbsaas.boot.rest.response.ListResponse;
import com.nbsaas.boot.rest.response.PageResponse;
import com.nbsaas.boot.rest.response.ResponseObject;
import com.nbsaas.boot.rest.annotations.CreateData;
import com.nbsaas.boot.rest.annotations.UpdateData;
import com.nbsaas.sample.user.api.domain.request.UserAddressDataRequest;
import com.nbsaas.sample.user.api.domain.request.UserAddressSearchRequest;
import com.nbsaas.sample.user.api.domain.response.UserAddressResponse;
import com.nbsaas.sample.user.api.domain.simple.UserAddressSimple;
import com.nbsaas.sample.user.api.apis.UserAddressApi;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
*  前端控制器
*/
@RequiresAuthentication
@RestController
@RequestMapping("/userAddress")
public class UserAddressFrontController {


    @Resource
    private UserAddressApi userAddressApi;


    @RequestMapping("/search")
   public PageResponse<UserAddressSimple> search(UserAddressSearchRequest request) {
        return userAddressApi.search(request);
    }

    @RequestMapping("/list")
    public ListResponse <UserAddressSimple> list(UserAddressSearchRequest request) {
        return userAddressApi.list(request);
    }

        /**
        * 添加数据
        *
        * @param request
        * @return
        */
    @CreateData
  @RequestMapping("/create")
   public ResponseObject<UserAddressResponse> create(@Validated(Add.class) UserAddressDataRequest request) {
       return userAddressApi.create(request);
    }

    @UpdateData
    @RequestMapping("/update")
   public ResponseObject
    <UserAddressResponse> update(@Validated(Update.class) UserAddressDataRequest request) {
         return userAddressApi.update(request);
    }

     @RequestMapping("/delete")
     public ResponseObject<?> delete(@Validated(Delete.class) UserAddressDataRequest request) {
        return userAddressApi.delete(request);
    }

    @RequestMapping("/view")
    public ResponseObject <UserAddressResponse> view(@Validated(View.class) UserAddressDataRequest request) {
         return userAddressApi.view(request);
    }
}
